#!/usr/bin/env ruby

"""System utility to display system information"""

require 'optparse'

options = {}

option_parser = OptionParser.new do |opts|
  # switches requires no parameters
	opts.on("-c", "--cpu", 'CPU 32-bit or 64-bit') do
		options[:cpu] = true
	end

	opts.on("-h", "--hostname", 'System hostname') do
		options[:hostname] = true
	end

	opts.on("-i", "--ipaddress", 'IP address') do
		options[:ipaddress] = true
	end

	opts.on("-u", "--uname", 'Output from uname') do
		options[:uname] = true
	end

	opts.on("-t", "--timezone", 'System timezone') do
		options[:timezone] = true
	end

	# flags take an argument
	opts.on("-p <hostname>", "--ping", 'Ping a host') do |pinghost|
		options[:pinghost] = pinghost
	end
	
end

option_parser.parse!

if options.length != 1
	puts option_parser.help
	exit 1
end

if options[:cpu]
	system('lscpu | grep Architecture | cut -d ":" -f 2 | sed \'s/\s*//g\'')
end

if options[:hostname]
	system('hostname')
end

if options[:ipaddress]
	system('hostname -i')
end

if options[:uname]
	system('uname -a')
end

if options[:timezone]
	system('cat /etc/timezone')
end

if options[:pinghost]
	system('ping ' + options[:pinghost])
end

